package com.ctshk.rpc.scenic.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.scenic.dto.TicketTypeLuckDrawNumDTO;
import com.ctshk.rpc.scenic.entity.TicketTypeLuckDraw;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 门票抽奖种类表 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-18
 */
public interface TicketTypeLuckDrawMapper extends BaseMapper<TicketTypeLuckDraw> {


    @Select("SELECT\n" +
            "\tt.session_code sessionCode,\n" +
            "\tt.discipline discipline,\n" +
            "\tt.sessions_name sessionsName,\n" +
            "\tt.competition_area competitionArea,\n" +
            "\tt.competition_date competitionDate,\n" +
            "\tt.competition_time competitionTime,\n" +
            "\tt.fare_basis fareBasis,\n" +
            "\tt.price price,\n" +
            "\tt.cn_discipline,\n" +
            "\tt.cn_sessions_name,\n" +
            "\tt.cn_competition_area,\n" +
            "\ttu.number number\n" +
            "FROM\n" +
            "\tt_ticket_luck_draw_apply_user_info u" +
            "\tleft join t_ticket_type_luck_draw_user tu on u.id = tu.user_info_id" +
            "\tleft join t_ticket_type_luck_draw t on t.id = tu.ticket_type_id" +
            "\tWHERE\n" +
            "\tu.query_number = #{queryNumber}")
    List<TicketTypeLuckDrawNumDTO> selectByQueryNumber(@Param("queryNumber") String queryNumber);

    @Update("update t_ticket_type_luck_draw " +
            "<foreach collection=\"ticketTypeLuckDrawList\" separator=\"\" item=\"draw\" open=\"id = #{draw.id}\" close=\"end, \">\n" +
            "when #{draw.id} then #{draw.number}\n" +
            "</foreach>"
    )
    int updateLuckDraw(@Param("ticketTypeLuckDrawList") List<TicketTypeLuckDraw> ticketTypeLuckDrawList);
}
